package com.sgb.member.ui.activity;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import com.google.android.material.tabs.TabLayout;
import com.sgb.member.R;
import com.sgb.member.databinding.ActivityPriceAdjustment2Binding;
import com.sgb.member.ui.fragment.PriceAdjustmentFragment2;
import com.swgk.core.base.AppActivity;
import com.swgk.core.customview.XCustomTabLayout;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

/**
 * 调价信息
 */
public class PriceAdjustmentActivity2 extends AppActivity {

    private final String[] mPriceTitle = {"商品调价", "租赁调价", "劳务调价"};

    public static void start(Context context) {
        Intent intent = new Intent(context, PriceAdjustmentActivity2.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        ActivityPriceAdjustment2Binding mBinding = DataBindingUtil.setContentView(this, R.layout.activity_price_adjustment_2);
        mBinding.activityBar.titleView.setText("会员调价");
        mBinding.activityBar.ivBack.setOnClickListener(v -> finish());

        ArrayList<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < mPriceTitle.length; i++) {
            fragments.add(PriceAdjustmentFragment2.newInstance(i, mPriceTitle[i]));
        }
        SlidingFragmentPagerAdapter adapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), fragments, mPriceTitle);
        mBinding.viewPager.setAdapter(adapter);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
        mBinding.tabLayout.setNormalColor(R.color.color_333333);
        mBinding.tabLayout.setSelectColor(R.color.color_main);
        mBinding.tabLayout.setNormalSize(14);
        mBinding.tabLayout.setSelectSize(14);

        mBinding.tabLayout.addOnTabSelectedListener(mPriceTitle, new XCustomTabLayout.SimpleSelectedListener(){
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mBinding.viewPager.setCurrentItem(tab.getPosition());
            }
        });
    }
}
